<template>
    <div>
      <commpVxeTable
        :isCanWrap="true"
        :key="reCommpVxeTable"
        :config="dataTableConfig"
        :columns="columnsVxe"
        :formItem="formItem"
        @checkboxChange="checkboxChange"
        ref="administrativeOffice"
        @searchEvent="searchEvent"
        @resetEvent="resetEvent"
        >
        <template v-slot:externalOperations="{data}"  >
            <vxe-form-item>
                <a-button class="blue-btn" @click="exportClick" icon="export">导出</a-button>
            </vxe-form-item>
        </template>
      </commpVxeTable>
    </div>
  </template>
  <script>
import {exportYszbczjlData} from './service/index'
  import assessCheckApi from './service/api.js'
  import commpVxeTable from '@/components/commp-vxe-table/commp-vxe-table.vue'
  import {} from './service/index.js'
  export default {
    components: {
      commpVxeTable,
    },
    props:{
    },
    data() {
      return {
        reCommpVxeTable: '',
        dataTableConfig: {
          api: assessCheckApi.list,
          rowId: 'id',
          urlType: true,
          paramet:{
          }
        },
        formItem: [
            {
                label: '预算指标台账名称',
                model: 'fystzmc',
            },{
            label: '操作人',
            model: 'fczr',
          },{
            label: '操作部门',
            model: 'fczbm',
          },{
            label: '操作方式',
            model: 'fczfs',
          },{
            label: '收支类型',
            model: 'fszlx',
          },
        ],
        columnsVxe: [
        {
            type: 'checkbox',
            width: 60 ,
            fixed: 'left'
        },{
            title: '操作人',
            field: 'fczr',
            width: 100,
          },{
            title: '操作部门',
            field: 'fczbm',
            width: 200,
          },{
            title: '操作时间',
            field: 'fczsj',
            width: 200,
          },{
            title: '操作方式',
            field: 'fczfs',
            width: 100,
          },{
            title: '预算指标台账名称',
            field: 'fystzmc',
          },{
            title: '预算指标名称',
            field: 'fyszbmc',
          },{
            title: '操作金额',
            field: 'fczje',
            width: 100,
          },
        ],
        idList: [],
        formData: {},
      }
    },
    methods: {
      // 勾选
      checkboxChange(val){
        //console.log('已选择',val)
        this.idList = []
        if(val.length){
          val.forEach(item => {
              this.idList.push(item.id)
          });
        }
      },
      // 搜索
      searchEvent(){
        this.dataTableConfig.paramet = {
            ...this.dataTableConfig.paramet,
        }
        //console.log(this.dataTableConfig.paramet)
      },
      // 重置
      resetEvent(){
        this.dataTableConfig.paramet = {
            ...this.dataTableConfig.paramet,
        }
      },
      exportClick(){
            let that = this
            if(that.idList.length == 0){
                that.$message.warning('请选择导出项')
            } else {
                that.$confirm({
                    title: '您确定要导出这些数据吗?',
                    content: '',
                    okText: '确定',
                    okType: 'info',
                    cancelText: '取消',
                    onOk() {
                        var fileName = '预算指标审计记录'
                        let list = that.idList.toString()
                        exportYszbczjlData({ids: list}).then((data) => {
                            // //console.log(data)
                            if (!data) {
                                that.$message.warning('文件下载失败')
                                return
                            }
                            if (typeof window.navigator.msSaveBlob !== 'undefined') {
                                window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xls')
                            } else {
                                let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
                                let link = document.createElement('a')
                                link.style.display = 'none'
                                link.href = url
                                link.setAttribute('download', fileName + '.xls')
                                document.body.appendChild(link)
                                link.click()
                                document.body.removeChild(link) //下载完成移除元素
                                window.URL.revokeObjectURL(url) //释放掉blob对象
                            }
                        })
                    },
                    onCancel() {
                        //console.log('Cancel');
                    },
                });
            }
        },
    },
  }
</script>
